import { TableColumnProps } from "ant-design-vue";
import { Ref } from "vue";
import { CURDDialogExpose, CURDModalEvent, FormItemData, ModelRules } from "/@/components/CURDDialog/models";
import { ProductFileItem } from "../pis/models";
import { SelectOptionItem } from "/@/types/antd";

export enum ActivityDefType {
  activitySchedule = "activitySchedule",
  activityCoupon = "activityCoupon",
  activityDetail = "activityDetail",
}

export enum AcitivityDefStatus {
  waiting = 0,
  passed = 1,
  disabled = 2,
}

export const AcitivityDefStatusDetail = {
  [AcitivityDefStatus.waiting]: { text: "待审核", color: "#7B879A" },
  [AcitivityDefStatus.passed]: { text: "审核通过", color: "#4285F4" },
  [AcitivityDefStatus.disabled]: { text: "作废", color: "#F56662" },
};

export enum ActivityType {
  tuan = 0,
  chang = 1,
  man = 2,
  jifen = 3,
  qiang = 4,
}

export enum ActivityCondition {
  all = 0,
  orderPrice = 1,
  orderClass = 2,
}

export enum ActivityConditionType {
  gte = 0,
  gt = 1,
  e = 2,
  lt = 3,
  lte = 4,
  ue = 5,
  include = 6,
  exclude = 7,
}

export enum ActivityCarrier {
  coupon = 0,
  product = 1,
}

export enum ObtainWays {
  give = 0,
  buy = 1,
  exchange = 2,
}

export enum CouponsScope {
  self = 0,
  dif = 1,
}

export interface AcitivityDefItem {
  _range: string[];
  //common
  id: number;
  reviewTime: number;
  reviewer: string;
  tabulationTime: number;
  tabulator: string;
  //schedule
  startDate: string;
  endDate: string;
  activityName: string;
  activityTheme: string;
  status: AcitivityDefStatus;
  //coupon
  couponsName: string;
  couponsUrl: string;
  couponsLogo: string;
  couponsValue: number | null;
  isPermanently: boolean;
  startPeriod: number;
  endPeriod: number;
  _periodRange: { range: string[]; isAll: boolean };
  _timeRange: { range: string[]; isAll: boolean };
  isAllDay: boolean;
  startTime: string;
  endTime: string;
  isCalcPoints: boolean | number;
  description: string;
  couponsScope: CouponsScope | null;
  productCategoryIdList: number[];
  productCategoryNameList: string[];
  goodsNameList: string[];
  unionNameList: string[];
  goodsIdList: number[];
  _typeProduct: { productCategoryList: Partial<SelectOptionItem>[]; goodsList: Partial<ProductFileItem>[] };
  unionIdList: number[];
  //
  activityScheduleId: number | null;
  activityScheduleName: string;
  activityDetailName: string;
  activityUrl: string;
  activityType: ActivityType;
  activityCondition: ActivityCondition;
  _activityCondition: null | {
    activityCondition: ActivityCondition;
    conditionType: ActivityConditionType;
    conditionValue: number | string | null;
  };
  conditionType: ActivityConditionType;
  conditionValue: number | null | string;
  activityCarrier: ActivityCarrier;
  _activityCarrier: null | {
    obtainWays: ObtainWays;
    goodsId?: number;
    goodsName?: string;
    couponsId?: string;
    couponsName?: string;
    activityCarrier: ActivityCarrier;
    consumeValue: number | null;
  };
  obtainWays: ObtainWays;
  consumeValue: number | null;
  putNum: number | null;
  isObtainLimit: boolean;
  obtainLimitNum: number | undefined;
  _obtainLimitNum: null | { isObtainLimit: boolean; obtainLimitNum: number | undefined };
  // startPeriod: number;
  // endPeriod: number;
  // isAllDay: boolean;
  activitySort: number;
  // description: string;
  // goodsIdList: number[];
  couponsIdList: number[];
  joinNum: number;
  goodsId: number;
  goods: ProductFileItem;
  couponsId: string;
  coupons: AcitivityDefItem;
  allowJoinTimes: number;
  communityId: number;
}

export interface UseActivityHookResult {
  addText: string;
  pageTitle: string;
  editText: string;
  deleteText: string;
  innerColumns: TableColumnProps<Partial<AcitivityDefItem>>[];
  model: Ref<Partial<AcitivityDefItem>>;
  modelFormSetting: Ref<FormItemData<Partial<AcitivityDefItem>>[]>;
  modelRules?: ModelRules;
  innerBeforeOk?: (e: CURDModalEvent<Partial<AcitivityDefItem>>) => void;
  innerOpen?: (e: CURDModalEvent<Partial<AcitivityDefItem>>) => void;
  curdDialogIns?: Ref<CURDDialogExpose | undefined>;
  getDetail?: (record: any) => Promise<Partial<AcitivityDefItem>>;
  beforeUpdateModel?: (e: any) => void;
}

export type UseActivityHook = () => UseActivityHookResult;
